﻿using Super.Admin.Entities;
using Super.Admin.Models.UserCommonPermission;

namespace Super.Admin.Mappers
{
    /// <summary>
    /// UserCommonPermissionMapper 类用于在 UserCommonPermissionEntity 和 UserCommonPermissionModel 之间进行转换。
    /// </summary>
    public static class UserCommonPermissionMapper
    {
        /// <summary>
        /// 将 UserCommonPermissionEntity 转换为 UserCommonPermissionBaseModel。
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static UserCommonPermissionBaseModel ToBaseModel(this UserCommonPermissionEntity entity)
        {
            if (entity == null) return null;
            return new UserCommonPermissionBaseModel
            {
                UserId = entity.UserId,
                PermissionId = entity.PermissionId,
            };
        }
        /// <summary>
        /// 将 UserCommonPermissionEntity 转换为 UserCommonPermissionDetailModel。
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static UserCommonPermissionDetailModel ToDetailModel(this UserCommonPermissionEntity entity)
        {
            if (entity == null) return null;
            return new UserCommonPermissionDetailModel
            {
                UserId = entity.UserId,
                PermissionId = entity.PermissionId,
                User = entity.User?.ToBaseModel(),
                Permission = entity.Permission?.ToBaseModel()
            };
        }
        /// <summary>
        /// 将 UserCommonPermissionBaseModel 转换为 UserCommonPermissionEntity。
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static UserCommonPermissionEntity ToEntity(this UserCommonPermissionBaseModel model)
        {
            if (model == null) return null;
            return new UserCommonPermissionEntity
            {
                UserId = model.UserId,
                PermissionId = model.PermissionId,
            };
        }
        /// <summary>
        /// 将 UserCommonPermissionDetailModel 转换为 UserCommonPermissionEntity。
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static UserCommonPermissionEntity ToEntity(this UserCommonPermissionDetailModel model)
        {
            if (model == null) return null;
            return new UserCommonPermissionEntity
            {
                UserId = model.UserId,
                PermissionId = model.PermissionId,
            };
        }
        /// <summary>
        /// 将 UserCommonPermissionEntity 列表转换为 UserCommonPermissionBaseModel 列表。
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        public static IEnumerable<UserCommonPermissionBaseModel> ToBaseModels(this IEnumerable<UserCommonPermissionEntity> entities)
        {
            return entities?.Select(e => e.ToBaseModel()).ToList() ?? new List<UserCommonPermissionBaseModel>();
        }
        /// <summary>
        /// 将 UserCommonPermissionEntity 列表转换为 UserCommonPermissionDetailModel 列表。
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        public static IEnumerable<UserCommonPermissionDetailModel> ToDetailModels(this IEnumerable<UserCommonPermissionEntity> entities)
        {
            return entities?.Select(e => e.ToDetailModel()).ToList() ?? new List<UserCommonPermissionDetailModel>();
        }
        /// <summary>
        /// 将 UserCommonPermissionBaseModel 列表转换为 UserCommonPermissionEntity 列表。
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public static IEnumerable<UserCommonPermissionEntity> ToEntities(this IEnumerable<UserCommonPermissionBaseModel> models)
        {
            return models?.Select(m => m.ToEntity()).ToList() ?? new List<UserCommonPermissionEntity>();
        }
        /// <summary>
        /// 将 UserCommonPermissionDetailModel 列表转换为 UserCommonPermissionEntity 列表。
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public static IEnumerable<UserCommonPermissionEntity> ToEntities(this IEnumerable<UserCommonPermissionDetailModel> models)
        {
            return models?.Select(m => m.ToEntity()).ToList() ?? new List<UserCommonPermissionEntity>();
        }
    }
}